package com.ruoyi.web.controller.email;

import com.ruoyi.approval.domain.ExamineAndApprove;
import com.ruoyi.approval.service.IExamineAndApproveService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
public class EmailSongConfig {
    @Autowired
    private JavaMailSender javaMailSender;

    @Autowired
    private IExamineAndApproveService examineAndApproveService;

    @RabbitListener(queues = "item_queue")
    public void email(EmailSong email) throws Exception {
        String from = "2934343875@qq.com"; //发送人
//         String to = "1633856539@qq.com";     // 接收人
//         String subject = "惊鸿办公";         // 邮件主题
//         String text = "<img src=''>";        // 邮件内容
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from+"(浩)");
        message.setTo(email.getTo());
        message.setSubject(email.getSubject());
        message.setText(email.getText());
        javaMailSender.send(message);
    }

    @RabbitListener(queues = "audit_queue")
    public void add(ExamineAndApprove examineAndApprove) throws Exception {
        examineAndApproveService.insertExamineAndApprove(examineAndApprove);
    }



}
